﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace BattleFury.Lib.Tiles
{
	public class Tileset
	{
		private readonly List<Rectangle> _bounds;

		public Texture2D Texture { get; private set; }
		public Vector2 TileSize { get; private set; }

		public Rectangle this[int index]
		{
			get { return _bounds[index]; }
		}

		public Tileset(Texture2D texture, Vector2 tileSize)
		{
			Texture = texture;
			TileSize = tileSize;

			_bounds = new List<Rectangle>();

			for (var y = 0; y < texture.Height / tileSize.Y; y++)
			{
				for (var x = 0; x < texture.Width / tileSize.X; x++)
				{
					var bounds = new Rectangle((int)(x * tileSize.X), (int)(y * tileSize.Y), (int) tileSize.X, (int) tileSize.Y);
					_bounds.Add(bounds);
				}
			}
		}
	}
}